package com.ssg.poultry.websocket;

import java.io.IOException;

import javax.websocket.CloseReason;
import javax.websocket.EndpointConfig;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;

import org.apache.log4j.Logger;

public abstract class BaseWebSocket {
	
	protected Logger logger = Logger.getLogger(this.getClass());
	protected Session session = null;
	
	
	@OnOpen
    public void onOpen(Session session, EndpointConfig config) {
		this.session = session;
	}
	
	@OnMessage
    public abstract void onMessage(Session session, String msg);
	
	@OnError
    public abstract void onError(Session session, Throwable throwable);
  
    @OnClose
    public abstract void onClose(Session session, CloseReason reason);
    
    protected void sendText(String msg) {
    	try {
			session.getBasicRemote().sendText(msg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
